/**
 * Particle Object definition
 */
var Particle = function(){
    this.x = 0;
    this.y = 0;
    this.vx = 0;
    this.vy = 0;
    this.r = 0;
    this.dt = 0.1;

    this.max_width = 0;
    this.max_height = 0;

    this.ctx = null;

    this.init = function(canvas){
        this.max_width = canvas.width;
        this.max_height = canvas.height;
        this.ctx = canvas.getContext('2d');
        this.x = Math.random() * canvas.width;
        this.y = Math.random() * canvas.height;
        this.vx = this.srandom() * 30;
        this.vy = this.srandom() * 30;
        this.r = Math.random() * 20 + 5;
    }

    this.draw = function(){
        this.ctx.beginPath();
        this.ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, false);
        this.ctx.closePath();
        this.ctx.fill();
    }

    this.update = function(){
        this.x += this.vx * this.dt;
        this.y += this.vy * this.dt;
        this.bound();
    }

    this.bound = function(){
        if (this.x < 0){
            this.x = 0; this.vx *= -1;
        }
        if (this.y < 0){
            this.y = 0; this.vy *= -1;
        }
        if (this.x > this.max_width - 1){
            this.x = this.max_width - 1;
            this.vx *= -1;
        }
        if (this.y > this.max_height - 1){
            this.y = this.max_height - 1;
            this.vy *= -1;
        }
    }


    this.srandom = function(){
        return Math.random() + 2 - 1;
    }

}